package com.ruoyi.web.controller.equipment;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.equipment.domain.ZjutEquipment;
import com.ruoyi.equipment.service.IZjutEquipmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 设备Controller
 *
 * @author ruoyi
 * @date 2021-04-09
 */
@RestController
@RequestMapping("/equipment/show")
public class ZjutEquipmentController extends BaseController
{
    @Autowired
    private IZjutEquipmentService zjutEquipmentService;

    /**
     * 查询设备列表
     */
    @PreAuthorize("@ss.hasPermi('equipment:show:list')")
    @GetMapping("/list")
    public TableDataInfo list(ZjutEquipment zjutEquipment)
    {
        startPage();
        List<ZjutEquipment> list = zjutEquipmentService.selectZjutEquipmentList(zjutEquipment);
        return getDataTable(list);
    }

    /**
     * 导出设备列表
     */
    @PreAuthorize("@ss.hasPermi('equipment:show:export')")
    @Log(title = "设备", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ZjutEquipment zjutEquipment)
    {
        List<ZjutEquipment> list = zjutEquipmentService.selectZjutEquipmentList(zjutEquipment);
        ExcelUtil<ZjutEquipment> util = new ExcelUtil<ZjutEquipment>(ZjutEquipment.class);
        return util.exportExcel(list, "show");
    }

    /**
     * 获取设备详细信息
     */
    @PreAuthorize("@ss.hasPermi('equipment:show:query')")
    @GetMapping(value = "/{equipmentId}")
    public AjaxResult getInfo(@PathVariable("equipmentId") Long equipmentId)
    {
        return AjaxResult.success(zjutEquipmentService.selectZjutEquipmentById(equipmentId));
    }

    /**
     * 新增设备
     */
    @PreAuthorize("@ss.hasPermi('equipment:show:add')")
    @Log(title = "设备", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ZjutEquipment zjutEquipment)
    {
        return toAjax(zjutEquipmentService.insertZjutEquipment(zjutEquipment));
    }

    /**
     * 修改设备
     */
    @PreAuthorize("@ss.hasPermi('equipment:show:edit')")
    @Log(title = "设备", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ZjutEquipment zjutEquipment)
    {
        return toAjax(zjutEquipmentService.updateZjutEquipment(zjutEquipment));
    }

    /**
     * 删除设备
     */
    @PreAuthorize("@ss.hasPermi('equipment:show:remove')")
    @Log(title = "设备", businessType = BusinessType.DELETE)
	@DeleteMapping("/{equipmentIds}")
    public AjaxResult remove(@PathVariable Long[] equipmentIds)
    {
        return toAjax(zjutEquipmentService.deleteZjutEquipmentByIds(equipmentIds));
    }
}
